'''
Created on 17/12/2010

@author: inyaky
'''

from google.appengine.ext import db


class Category(db.Model):

    _name = db.StringProperty()
    _owner = db.UserProperty()
    _fieldsNames = db.ListProperty(str)
    _fieldsTypes = db.ListProperty(int)
    _fieldsRequ = db.ListProperty(bool)
    
    def setName (self,aName):
        self._name = aName
        self.put()
        
    def getName (self):
        return self._name
    
    def setOwner (self,aOwner):
        self._owner = aOwner
        self.put()
        
    def getOwner (self):
        return self._owner
    
    def addField(self,fieldName,fieldType,aFieldReq):
        self._fieldsNames = self._fieldsNames + [fieldName]
        self._fieldsTypes = self._fieldsTypes + [fieldType]
        self._fieldsRequ = self._fieldsRequ + [aFieldReq]
        self.put()
        
    def getFields(self):
        aux = []
        i=0
        for aName in self._fieldsNames:
            aux = aux + [{'fName':aName,'fType':self._fieldsTypes[i], 'fReq':self._fieldsRequ[i] }]
            i=i+1
        return aux
    
    def toRenderable(self):
        return [{'name':self.getName(), 'key':self.key()}]
    
            
            
            
        
        